//
//  MianViewController.swift
//  ScrollTabBarController
//
//  Created by 好米有易 on 2017/11/13.
//  Copyright © 2017年 好米有易. All rights reserved.
//

import UIKit

class MianViewController: ScrollTabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        self.tabBarView.itemTintColor = UIColor.red
        
        loadItems()
    }
    
    
    
}


// MARK: - Data
extension MianViewController {
    
    fileprivate func loadData() -> [[String:Any]] {
    
        let itemInfo = [["vcName":FirstViewController(), "imageName":"tab_home_normal", "selectedImage":"tab_home_pressed", "title":"First"],
                        ["vcName":SecondViewController(), "imageName":"tab_list_normal", "selectedImage":"tab_list_preesed", "title":"Second"],
                        ["vcName":ThirdViewController(), "imageName":"tab_account_normal", "selectedImage":"tab_account_pressed", "title":"Third"],
                        ["vcName":FourthViewController(), "imageName":"tab_more_normal", "selectedImage":"tab_more_preesed", "title":"Fourth"]
        ]
        
        return itemInfo
    }
    
}


// MARK: - UI
extension MianViewController {
    
    fileprivate func loadItems() {
        
        let temArr = loadData()
        
        
        for(_, item) in temArr.enumerated() {
    
            let vc: UIViewController = item["vcName"] as! UIViewController
            
            vc.tabBarItem.image = UIImage(named: item["imageName"] as! String)
            
            vc.tabBarItem.selectedImage = UIImage(named: item["selectedImage"] as! String)
            
            vc.title = item["title"] as? String
            
            itemWith(childViewController: vc)
            
        }
        

    }
    
    fileprivate func itemWith(childViewController: UIViewController) {
        
        let nav = CustonNavController(rootViewController: childViewController)
        
        addChildViewController(nav)
        
    }
    
    
}
